<?php
/***************************************************************************
 * 
 * Copyright (c) 2010 , Inc. All Rights Reserved
 * $Id$ 
 * 
 **************************************************************************/
 
 
 
/**
 * @file ValidationIntTest.php
 * @author niulei(niulei@)
 * @date 2010/05/17 18:58:28
 * @version $Revision$ 
 * @brief 
 *  
 **/
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'validate/Validation.php';

class ValidationIntTest extends PHPUnit_Framework_TestCase{

    protected function setUp()
    {			
       sleep(1);
    }
    
    public function testNoneChecked(){
    	$arr_rules = array(
    	                    'func' => 'INT',
    	                    //'flag' => array(
                             //               'FLAG_ALLOW_EMPTY',
                             //              ),
                            //'min_range'=>0,//最小
                            //'max_range'=>100,//最大
                            //'value_array'=>array(1,2,3),//可选值
    	                   );
    	$input = "-18";
    	$this->assertTrue(Validation::check($input,$arr_rules));
    	$input = "18.6";
    	$this->assertContains("Length checked", Validation::check($input,$arr_rules));
    }

    public function testEmptyChecked(){
    	$input = "";
    	$arr_rules = array(
    	                    'func' => 'INT',
    	                    'flag' => array(
                                            //'FLAG_ALLOW_EMPTY',
                                           ),
                            'min_range'=>-100,//最小长度
                            'max_range'=>100,//最大长度
    	                   );
        $this->assertContains("Empty checked", Validation::check($input,$arr_rules));
        $arr_rules['flag'] = array(
                                    'FLAG_ALLOW_EMPTY',
                                   );
        $this->assertTrue(Validation::check($input,$arr_rules));
    }
    
    public function testLengthChecked(){
    	$input = "180";
    	$arr_rules = array(
    	                    'func' => 'INT',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY'
                                           ),
                            'min_range'=>0,
                            'max_range'=>100,
    	                   );
        
        $this->assertContains("Length checked", Validation::check($input,$arr_rules));
        $arr_rules['max_range'] = 200;
        $this->assertTrue(Validation::check($input,$arr_rules));
        $input = "180.33333";
        $this->assertContains("Length checked", Validation::check($input,$arr_rules));
        $arr_rules['min_range'] = 190;
        $input = "180";
        $this->assertContains("Length checked", Validation::check($input,$arr_rules));        
    }
    
    public function testLengthComplexChecked(){
    	$input = "-100.01";
    	$arr_rules = array(
    	                    'func' => 'INT',
    	                    'flag' => array(
                                            'FLAG_ALLOW_EMPTY'
                                           ),
                            'min_range'=>-100,
                            'max_range'=>100,
    	                   );
        
        $this->assertContains("Length checked", Validation::check($input,$arr_rules));
        $input = "000099";
        $this->assertContains("Length checked", Validation::check($input,$arr_rules));
        $input = "0000000";
        $this->assertContains("Length checked", Validation::check($input,$arr_rules));
    }
    
    public function testContentChecked(){
    	$input = "180";
    	$arr_rules = array(
    	                    'func' => 'INT',
    	                    'flag' => array(
    	                                    'FLAG_ALLOW_EMPTY',
                                           ),
                            'min_range'=>0,
                            'max_range'=>200,
                            'value_array'=>array(1,2,180,200),
    	                   );
        $this->assertTrue(Validation::check($input,$arr_rules));

        $arr_rules['value_array'] = array(1,2,200);
        $this->assertContains("Value checked", Validation::check($input,$arr_rules));
    }
}
?>
